﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using LunarPhase.Model;

namespace LunarPhase.Test
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class MoonTest
    {
        public MoonTest()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void AmoonMustHaveAdate()
        {
            DateTime expectedDate = DateTime.Now;
            Moon aMoon = new Moon();
            Assert.AreEqual<DateTime>(expectedDate, aMoon.Date);
        }

        #region Light test
        [TestMethod]
        public void NewMoonHasZeroLight()
        {
            DateTime newMoonDay = TestHelper.GetAnewMoonDay();
            Moon newMoon = new Moon(newMoonDay);
            int expected = 0;
            Assert.AreEqual<double>(expected, newMoon.PercentageIlluminated);
        }

        [TestMethod]
        public void WaningGibbousMoonHas75PLight()
        {
            DateTime waningGibbousMoonDay = TestHelper.GetAwaningGibbousMoonDay();
            Moon newMoon = new Moon(waningGibbousMoonDay);
            int expected = 75;
            Assert.AreEqual<double>(expected, newMoon.PercentageIlluminated);
        }

        [TestMethod]
        public void FistQuarterMoonHas50PLight()
        {
            DateTime fistQuarterMoonDay = TestHelper.GetAfirstQuarterMoonDay();
            Moon newMoon = new Moon(fistQuarterMoonDay);
            int expected = 50;
            Assert.AreEqual<double>(expected, newMoon.PercentageIlluminated);
        }

        [TestMethod]
        public void FullMoonMoonHas100PLight()
        {
            DateTime fullMoonDay = TestHelper.GetAfullMoonDay();
            Moon newMoon = new Moon(fullMoonDay);
            int expected = 100;
            Assert.AreEqual<double>(expected, newMoon.PercentageIlluminated);
        }

        [TestMethod]
        public void WaxingCrescentMoonHas25PLight()
        {
            DateTime waxingCrescentMoonDay = TestHelper.GetAwaxingCrescentMoonDay();
            Moon newMoon = new Moon(waxingCrescentMoonDay);
            int expected = 25;
            Assert.AreEqual<double>(expected, newMoon.PercentageIlluminated);
        }

        [TestMethod]
        public void WaxingGibbousMoonHas75PLight()
        {
            DateTime waxingGibbousMoonDay = TestHelper.GetAwaxingGibbousMoonDay();
            Moon newMoon = new Moon(waxingGibbousMoonDay);
            int expected = 75;
            Assert.AreEqual<double>(expected, newMoon.PercentageIlluminated);
        }

        [TestMethod]
        public void LastQuarterMoonHas50PLight()
        {
            DateTime lastQuarterMoonDay = TestHelper.GetAlastQuarterMoonDay();
            Moon newMoon = new Moon(lastQuarterMoonDay);
            int expected = 50;
            Assert.AreEqual<double>(expected, newMoon.PercentageIlluminated);
        }

        [TestMethod]
        public void WanningCrescentMoonHas25PLight()
        {
            DateTime wanningCrescentMoonDay = TestHelper.GetAwanningCrescentMoonDay();
            Moon newMoon = new Moon(wanningCrescentMoonDay);
            int expected = 25;
            Assert.AreEqual<double>(expected, newMoon.PercentageIlluminated);
        }

        [TestMethod]
        public void MoonWithMaxAgeHasZeroLight()
        {
            DateTime newMoonDay = TestHelper.GetAmaxNewMoonDay();
            Moon newMoon = new Moon(newMoonDay);
            int expected = 0;
            Assert.AreEqual<double>(expected, newMoon.PercentageIlluminated);
        }

        #endregion

        [TestMethod]
        public void ToStringReturnPhaseName()
        {
            Moon expected = new Moon();
            Assert.AreEqual<string>(expected.Phase.ToString(), expected.ToString());
        }

        [TestMethod]
        public void TopLightAgeIsAhalfOfMaxAge()
        {
            double expected = Moon.MaxMoonAge/2;
            Assert.AreEqual<double>(expected, Moon.TopLightAge);
        }

        [TestMethod]
        public void DefaultConstructorCreateTodayMoon()
        {
            Moon todayMoon = new Moon();
            DateTime today = DateTime.Now;
            Assert.AreEqual<double>(today.Day, todayMoon.Date.Day);
        }

        [TestMethod]
        public void PercentageIlluminatedTest()
        {
            Moon_Accessor moon = new Moon_Accessor();
            moon.PercentageIlluminated = 100;
            double expected = 100;
            Assert.AreEqual<double>(expected, moon.PercentageIlluminated);
        }

        [TestMethod]
        public void MoonsAreEqualsWithSameDate()
        {
            Moon moon = new Moon(DateTime.Now);
            Moon otherMoon = new Moon(DateTime.Now);
            Assert.AreEqual<Moon>( moon, otherMoon);
        }

        [TestMethod]
        public void MoonsAreNotEqualsWithNull()
        {
            Moon moon = new Moon(DateTime.Now);
            Moon nullMoon = null;
            Assert.AreNotEqual<Moon>(moon, nullMoon);
        }

    }
}
